using UnityEngine;

namespace Crosstales.Common.Util
{
    // [Assembly-CSharp-firstpass.dll].Crosstales.Common.Util.FileHelper
    public abstract class FileHelper
    {
        
        #region Crosstales.Common.Util.FileHelper.<>c
        // [Assembly-CSharp-firstpass.dll].Crosstales.Common.Util.FileHelper.<>c
        [Serializable]
        private sealed class __c
        {
            // Fields
            public static readonly Crosstales.Common.Util.FileHelper.<>c __9;
            public static System.Func<string, bool> __9__9_0;
            public static System.Func<string, string> __9__9_1;
            
            // Methods
            private static __c()
            {
                object val_1 = 536898647;
                val_1 = new System.Object();
                mem2[0] = val_1;
                throw new NullReferenceException();
            }
            public __c()
            {
            
            }
            internal bool <GetFilesForName>b__9_0(string extension)
            {
                if((extension.Equals(value:  -1610611753)) == false)
                {
                        return extension.Equals(value:  -1610611747);
                }
                
                return true;
            }
            internal string <GetFilesForName>b__9_1(string q)
            {
                return (string)q;
            }
        
        }
        
        #endregion
        
        // Fields
        private static string applicationDataPath;
        
        // Properties
        public static string StreamingAssetsPath { get; }
        
        // Methods
        public static string get_StreamingAssetsPath()
        {
            var val_2;
            bool val_1 = Crosstales.Common.Util.BaseHelper.isEditor;
            val_2 = 536886029;
            if(mem[536886253] != 0)
            {
                    return -1610597719(-1610597719) + mem[536886213] + -1610612313(-1610612313);
            }
            
            val_2 = 536886029;
            return -1610597719(-1610597719) + mem[536886213] + -1610612313(-1610612313);
        }
        private static FileHelper()
        {
            mem2[0] = UnityEngine.Application.dataPath;
            Crosstales.Common.Util.FileHelper.initialize();
        }
        private static void initialize()
        {
            if(mem[536886253] == 0)
            {
                    536886029 = 536886029;
            }
            
            mem2[0] = UnityEngine.Application.dataPath;
        }
        public static string ValidatePath(string path, bool addEndDelimiter = True, bool preserveFile = True)
        {
            string val_15;
            if((System.String.IsNullOrEmpty(value:  path)) == true)
            {
                    return (string)path;
            }
            
            if((Crosstales.Common.Util.NetworkHelper.isValidURL(url:  path)) != false)
            {
                    return (string)path;
            }
            
            if(preserveFile != false)
            {
                    if(path != null)
            {
                goto label_7;
            }
            
            }
            
            if((System.IO.File.Exists(path:  path.Trim())) != false)
            {
                    string val_6 = System.IO.Path.GetDirectoryName(path:  path.Trim());
            }
            else
            {
                    label_7:
            }
            
            bool val_8 = Crosstales.Common.Util.BaseHelper.isWindowsBasedPlatform;
            val_15 = path.Trim().Replace(oldChar:  '\', newChar:  '/');
            if(addEndDelimiter == false)
            {
                    return System.String.Join(separator:  mem[536893213], value:  val_15.Split(separator:  System.IO.Path.GetInvalidPathChars()));
            }
            
            if((Crosstales.ExtensionMethods.CTEndsWith(str:  val_15, toCheck:  -1610611453, comp:  5)) == true)
            {
                    return System.String.Join(separator:  mem[536893213], value:  val_15.Split(separator:  System.IO.Path.GetInvalidPathChars()));
            }
            
            val_15 = val_15 + -1610611453(-1610611453);
            return System.String.Join(separator:  mem[536893213], value:  val_15.Split(separator:  System.IO.Path.GetInvalidPathChars()));
        }
        public static string ValidateFile(string path)
        {
            string val_16;
            if((System.String.IsNullOrEmpty(value:  path)) == true)
            {
                    return (string)path;
            }
            
            if((Crosstales.Common.Util.NetworkHelper.isValidURL(url:  path)) != false)
            {
                    return (string)path;
            }
            
            val_16 = Crosstales.Common.Util.FileHelper.ValidatePath(path:  path, addEndDelimiter:  true, preserveFile:  true);
            if((Crosstales.ExtensionMethods.CTEndsWith(str:  val_16, toCheck:  -1610601009, comp:  5)) != true)
            {
                    if((Crosstales.ExtensionMethods.CTEndsWith(str:  val_16, toCheck:  -1610611453, comp:  5)) == false)
            {
                goto label_7;
            }
            
            }
            
            val_16 = val_16.Substring(startIndex:  0, length:  val_3._stringLength - 1);
            label_7:
            bool val_8 = Crosstales.Common.Util.BaseHelper.isWindowsBasedPlatform;
            string val_16 = -1610611453;
            val_16 = (Crosstales.ExtensionMethods.CTLastIndexOf(str:  val_16, toCheck:  val_16, comp:  5)) + 1;
            return val_16.Substring(startIndex:  0, length:  val_7._stringLength - val_10._stringLength)(val_16.Substring(startIndex:  0, length:  val_7._stringLength - val_10._stringLength)) + System.String.Join(separator:  mem[536893213], value:  val_16.Substring(startIndex:  val_16).Split(separator:  System.IO.Path.GetInvalidFileNameChars()))(System.String.Join(separator:  mem[536893213], value:  val_16.Substring(startIndex:  val_16).Split(separator:  System.IO.Path.GetInvalidFileNameChars())));
        }
        public static bool PathHasInvalidChars(string path)
        {
            if((System.String.IsNullOrEmpty(value:  path)) != false)
            {
                    return (bool)val_3;
            }
            
            int val_3 = path.IndexOfAny(anyOf:  System.IO.Path.GetInvalidPathChars());
            val_3 = (~val_3) >> 31;
            return (bool)val_3;
        }
        public static bool FileHasInvalidChars(string file)
        {
            if((System.String.IsNullOrEmpty(value:  file)) != false)
            {
                    return (bool)val_3;
            }
            
            int val_3 = file.IndexOfAny(anyOf:  System.IO.Path.GetInvalidFileNameChars());
            val_3 = (~val_3) >> 31;
            return (bool)val_3;
        }
        public static string[] GetFilesForName(string path, bool isRecursive = False, string[] filenames)
        {
            System.Func<System.Object, System.Boolean> val_18;
            var val_19;
            System.Func<Unknown, System.Boolean> val_20;
            var val_21;
            System.Func<System.Object, System.Boolean> val_22;
            var val_23;
            System.Func<System.Object, System.Object> val_24;
            val_18 = 27342680;
            bool val_1 = Crosstales.Common.Util.BaseHelper.isWebPlatform;
            if((System.String.IsNullOrEmpty(value:  path)) != false)
            {
                    val_19 = mem[mem[3221292585] + 184];
                val_19 = mem[3221292585] + 184;
                return (Unknown)System.Linq.Enumerable.ToArray<System.Object>(source:  System.IO.Directory.EnumerateFiles(path:  string val_4 = Crosstales.Common.Util.FileHelper.ValidatePath(path:  path, addEndDelimiter:  true, preserveFile:  true), searchPattern:  -1610611753, searchOption:  isRecursive));
            }
            
            val_18 = 27346464;
            bool val_3 = Crosstales.Common.Util.BaseHelper.isWSABasedPlatform;
            val_20 = 1;
            if((filenames == null) || (filenames.Length == 0))
            {
                    return (Unknown)System.Linq.Enumerable.ToArray<System.Object>(source:  System.IO.Directory.EnumerateFiles(path:  val_4, searchPattern:  -1610611753, searchOption:  isRecursive));
            }
            
            val_21 = 536898647;
            if(mem[536898871] == 0)
            {
                    val_21 = 536898647;
            }
            
            val_18 = mem[mem[536898831] + 8];
            val_18 = mem[536898831] + 8;
            if(val_18 == 0)
            {
                    if(mem[536898871] == 0)
            {
                    val_21 = 536898647;
            }
            
                val_22 = 536903187;
                val_18 = val_22;
                if(val_22 == 0)
            {
                    throw new NullReferenceException();
            }
            
                val_18 = new System.Func<System.Object, System.Boolean>(object:  mem[536898831], method:  1610683663);
                mem2[0] = val_18;
            }
            
            val_20 = val_18;
            if((System.Linq.Enumerable.Any<System.Object>(source:  filenames, predicate:  val_20)) != false)
            {
                    return (Unknown)System.Linq.Enumerable.ToArray<System.Object>(source:  System.IO.Directory.EnumerateFiles(path:  val_4, searchPattern:  -1610611753, searchOption:  isRecursive));
            }
            
            val_22 = 536877495;
            if(val_22 == 0)
            {
                    throw new NullReferenceException();
            }
            
            val_20 = -1073676535;
            val_22 = val_22;
            val_22 = new System.Collections.Generic.List<System.Object>();
            Unknown val_17 = filenames.Length;
            if(val_17 >= 1)
            {
                    var val_18 = 0;
                val_17 = val_17 & 4294967295;
                do
            {
                if(val_18 >= val_17)
            {
                    throw new NullReferenceException();
            }
            
                val_22.AddRange(collection:  System.IO.Directory.EnumerateFiles(path:  val_4, searchPattern:  (null == 0) ? -1610612735 : (null), searchOption:  isRecursive));
                val_18 = val_18 + 1;
            }
            while(val_18 < (filenames.Length << ));
            
            }
            
            val_23 = 536898647;
            if(mem[536898871] == 0)
            {
                    val_23 = 536898647;
            }
            
            val_24 = mem[mem[536898831] + 16];
            val_24 = mem[536898831] + 16;
            if(val_24 == 0)
            {
                    if(mem[536898871] == 0)
            {
                    val_23 = 536898647;
            }
            
                val_24 = 536875183;
                val_24 = new System.Func<System.Object, System.Object>(object:  mem[536898831], method:  1610683665);
                mem2[0] = val_24;
            }
            
            Unknown val_15 = System.Linq.Enumerable.ToArray<System.Object>(source:  System.Linq.Enumerable.OrderBy<System.Object, System.Object>(source:  val_22, keySelector:  val_24));
            return (Unknown)System.Linq.Enumerable.ToArray<System.Object>(source:  System.IO.Directory.EnumerateFiles(path:  val_4, searchPattern:  -1610611753, searchOption:  isRecursive));
        }
        public static string[] GetFiles(string path, bool isRecursive = False, string[] extensions)
        {
            var val_3;
            Unknown val_4;
            val_3 = 27342680;
            val_4 = extensions;
            bool val_1 = Crosstales.Common.Util.BaseHelper.isWSABasedPlatform;
            if((val_4 == null) || (extensions.Length == 0))
            {
                goto label_3;
            }
            
            Unknown val_3 = extensions.Length;
            if(val_3 >= 1)
            {
                    var val_4 = 0;
                val_3 = val_3 & 4294967295;
                do
            {
                if(val_4 >= val_3)
            {
                    throw new NullReferenceException();
            }
            
                if(val_4 >= mem[536881491])
            {
                    throw new NullReferenceException();
            }
            
                mem[536881499] = -1610611749(-1610611749) + null;
                val_4 = val_4 + 1;
                val_3 = 536881507;
            }
            while(val_4 < (extensions.Length << ));
            
            }
            
            val_4 = 536881467;
            if(mem[536886253] != 0)
            {
                goto label_13;
            }
            
            val_4 = 536881467;
            goto label_13;
            label_3:
            label_13:
            isRecursive = isRecursive;
            return Crosstales.Common.Util.FileHelper.GetFilesForName(path:  path, isRecursive:  isRecursive, filenames:  val_4);
        }
        public static string[] GetDirectories(string path, bool isRecursive = False)
        {
            var val_8;
            bool val_1 = Crosstales.Common.Util.BaseHelper.isWebPlatform;
            bool val_2 = Crosstales.Common.Util.BaseHelper.isWSABasedPlatform;
            if((System.String.IsNullOrEmpty(value:  path)) == false)
            {
                    return (Unknown)System.Linq.Enumerable.ToArray<System.Object>(source:  System.IO.Directory.EnumerateDirectories(path:  Crosstales.Common.Util.FileHelper.ValidatePath(path:  path, addEndDelimiter:  true, preserveFile:  true), searchPattern:  -1610611753, searchOption:  isRecursive));
            }
            
            val_8 = mem[mem[3221292585] + 184];
            val_8 = mem[3221292585] + 184;
            return (Unknown)System.Linq.Enumerable.ToArray<System.Object>(source:  System.IO.Directory.EnumerateDirectories(path:  Crosstales.Common.Util.FileHelper.ValidatePath(path:  path, addEndDelimiter:  true, preserveFile:  true), searchPattern:  -1610611753, searchOption:  isRecursive));
        }
        public static string[] GetDrives()
        {
            bool val_1 = Crosstales.Common.Util.BaseHelper.isWebPlatform;
            bool val_2 = Crosstales.Common.Util.BaseHelper.isWSABasedPlatform;
            return (Unknown)System.IO.Directory.GetLogicalDrives();
        }
        public static void CopyPath(string sourcePath, string destPath, bool move = False)
        {
            object val_11;
            string val_12;
            var val_13;
            val_11 = 27342680;
            val_12 = destPath;
            bool val_1 = Crosstales.Common.Util.BaseHelper.isWSABasedPlatform;
            bool val_2 = Crosstales.Common.Util.BaseHelper.isWebPlatform;
            if((System.String.IsNullOrEmpty(value:  val_12)) == true)
            {
                    return;
            }
            
            if((System.IO.Directory.Exists(path:  sourcePath)) == false)
            {
                goto label_4;
            }
            
            if((System.IO.Directory.Exists(path:  val_12)) != false)
            {
                    val_11 = 27342664;
                val_13 = 536882899;
                if(mem[536883123] == 0)
            {
                    val_13 = 536882899;
            }
            
                if((mem[536883083] + 72) != 0)
            {
                    val_11 = -1610604673(-1610604673) + val_12;
                UnityEngine.Debug.LogWarning(message:  val_11);
            }
            
                System.IO.Directory.Delete(path:  val_12, recursive:  true);
            }
            
            if(move == false)
            {
                goto label_9;
            }
            
            System.IO.Directory.Move(sourceDirName:  sourcePath, destDirName:  val_12);
            return;
            label_4:
            val_12 = -1610603707(-1610603707) + sourcePath;
            UnityEngine.Debug.LogError(message:  val_12);
            return;
            label_9:
            val_11 = 536885173;
            if(536885173 == 0)
            {
                    throw new NullReferenceException();
            }
            
            val_11 = new System.IO.DirectoryInfo(path:  sourcePath);
            536885173 = new System.IO.DirectoryInfo(path:  val_12);
            Crosstales.Common.Util.FileHelper.copyAll(source:  val_11, target:  536885173);
        }
        public static void CopyFile(string sourceFile, string destFile, bool move = False)
        {
            object val_10;
            string val_11;
            var val_12;
            val_10 = 27342680;
            val_11 = sourceFile;
            bool val_1 = Crosstales.Common.Util.BaseHelper.isWSABasedPlatform;
            bool val_2 = Crosstales.Common.Util.BaseHelper.isWebPlatform;
            if((System.String.IsNullOrEmpty(value:  destFile)) == true)
            {
                    return;
            }
            
            if((System.IO.File.Exists(path:  val_11)) == false)
            {
                goto label_4;
            }
            
            System.IO.DirectoryInfo val_6 = System.IO.Directory.CreateDirectory(path:  System.IO.Path.GetDirectoryName(path:  destFile));
            if((System.IO.File.Exists(path:  destFile)) != false)
            {
                    val_10 = 27342664;
                val_12 = 536882899;
                if(mem[536883123] == 0)
            {
                    val_12 = 536882899;
            }
            
                if((mem[536883083] + 72) != 0)
            {
                    val_10 = -1610604671(-1610604671) + destFile;
                UnityEngine.Debug.LogWarning(message:  val_10);
            }
            
                System.IO.File.Delete(path:  destFile);
            }
            
            if(move == false)
            {
                goto label_10;
            }
            
            System.IO.File.Copy(sourceFileName:  val_11, destFileName:  destFile);
            System.IO.File.Delete(path:  val_11);
            return;
            label_4:
            val_11 = -1610603705(-1610603705) + val_11;
            UnityEngine.Debug.LogError(message:  val_11);
            return;
            label_10:
            System.IO.File.Copy(sourceFileName:  val_11, destFileName:  destFile);
        }
        public static void ShowPath(string path)
        {
            Crosstales.Common.Util.FileHelper.ShowFile(file:  536886029);
        }
        public static void ShowFile(string file)
        {
            bool val_1 = Crosstales.Common.Util.BaseHelper.isStandalonePlatform;
            bool val_2 = Crosstales.Common.Util.BaseHelper.isEditor;
            UnityEngine.Debug.LogWarning(message:  -1610611967);
        }
        public static void OpenFile(string file)
        {
            bool val_1 = Crosstales.Common.Util.BaseHelper.isStandalonePlatform;
            bool val_2 = Crosstales.Common.Util.BaseHelper.isEditor;
            UnityEngine.Debug.LogWarning(message:  -1610611971);
        }
        private static void copyAll(System.IO.DirectoryInfo source, System.IO.DirectoryInfo target)
        {
            System.IO.FileInfo val_7;
            string val_8;
            System.IO.DirectoryInfo val_1 = System.IO.Directory.CreateDirectory(path:  target);
            if(val_2.Length >= 1)
            {
                    var val_7 = 0;
                do
            {
                if(val_7 >= val_2.Length)
            {
                    throw new NullReferenceException();
            }
            
                val_7 = source.GetFiles()[val_7];
                val_8 = val_7;
                System.IO.FileInfo val_4 = val_7.CopyTo(destFileName:  System.IO.Path.Combine(path1:  target, path2:  val_8), overwrite:  true);
                val_7 = val_7 + 1;
            }
            while(val_7 < val_2.Length);
            
            }
            
            if(val_5.Length < 1)
            {
                    return;
            }
            
            val_8 = 27346464;
            var val_9 = 0;
            do
            {
                if(val_9 >= val_5.Length)
            {
                    throw new NullReferenceException();
            }
            
                val_7 = target.CreateSubdirectory(path:  source.GetDirectories()[val_9]);
                val_9 = val_9 + 1;
            }
            while(val_9 < val_5.Length);
        
        }
        protected FileHelper()
        {
        
        }
    
    }

}
